package cn.sciento.farm.devicemanager.gateway.model.inverter;


import cn.sciento.farm.devicemanager.common.util.NumberUtil;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class InverterRealData {

    private static final float MIN_PRESS = 0.5F;
    private static  final float MAX_PRESS = 15F;

    private String eui;

    private Integer id;

    private Float givenPress;
    private Float hyperPress;
    private Float lowPress;
    private Integer status;
    private Integer fault;
    private Float freq;
    private Float voltage;
    private Float current;
    private Float realPress;
    private Float temper;

    public InverterRealData() {
    }
    public InverterRealData(InverterUplinkPacket uplinkPacket) {
        this.id = uplinkPacket.getId();
        if(uplinkPacket.getGivenPress() != null){
            this.givenPress = NumberUtil.float2float(uplinkPacket.getGivenPress() *0.01f,2);
            if(this.givenPress < MIN_PRESS || this.givenPress > MAX_PRESS){
                this.givenPress = null;
            }
        }
        if(uplinkPacket.getHyperPress() != null){
            this.hyperPress = NumberUtil.float2float(uplinkPacket.getHyperPress() *0.01f,2);
        }
        if(uplinkPacket.getLowPress() != null){
            this.lowPress = NumberUtil.float2float(uplinkPacket.getLowPress() *0.01f,2);
        }
        if(uplinkPacket.getStatus() != null){
            this.status = uplinkPacket.getStatus();
        }
        if(uplinkPacket.getFault() != null){
            this.fault = uplinkPacket.getFault();
        }
        if(uplinkPacket.getFreq() != null){
            this.freq = NumberUtil.float2float(uplinkPacket.getFreq() *0.01f,2);
        }
        if(uplinkPacket.getVoltage() != null){
            this.voltage = NumberUtil.float2float(uplinkPacket.getVoltage() *0.1f,1);
        }
        if(uplinkPacket.getCurrent() != null){
            this.current = NumberUtil.float2float(uplinkPacket.getCurrent() *0.1f,1);
        }
        if(uplinkPacket.getRealPress() != null){
            this.realPress = NumberUtil.float2float(uplinkPacket.getRealPress()*0.01f,2);
        }
        if(uplinkPacket.getTemper() != null){
            this.temper = uplinkPacket.getTemper()*1f;
        }
    }

    public boolean isStatusData(){
        if(status != null  || givenPress != null || hyperPress != null || lowPress != null ){
            return true;
        }
        return false;
    }

}
